<!DOCTYPE html>
<html>
<head><meta charset="utf-8" />
<title>204-自省</title>

<script src="/lib/require/index.js"></script>
<script src="/lib/jquery/index.js"></script>

<!-- 改为引入外部样式 -->
<link rel="stylesheet" href="/css/custom.css">

<!-- Loading mathjax macro -->
<!-- Load mathjax -->
    <script src="/lib/mathjax/index.js"></script>
    <!-- MathJax configuration -->
    <script type="text/x-mathjax-config">
    MathJax.Hub.Config({
        tex2jax: {
            inlineMath: [ ['$','$'], ["\\(","\\)"] ],
            displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
            processEscapes: true,
            processEnvironments: true
        },
        // Center justify equations in code and markdown cells. Elsewhere
        // we use CSS to left justify single line equations in code cells.
        displayAlign: 'center',
        "HTML-CSS": {
            styles: {'.MathJax_Display': {"margin": 0}},
            linebreaks: { automatic: true }
        }
    });
    </script>
    <!-- End of mathjax configuration --></head>
<body>
<div class="toc">
<ul>
                        
                        
                        <li class="toc-li-2">
                            <a href="#自省">自省</a>
                        </li>
                    
                
            
            
            
            
                        
                        
                        <li class="toc-li-3">
                            <a href="#联机帮助">联机帮助</a>
                        </li>
                    
                
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
                        
                        
                        <li class="toc-li-3">
                            <a href="#dir()">dir()</a>
                        </li>
                    
                
            
            
            
            
            
            
                        
                        
                        <li class="toc-li-3">
                            <a href="#检查python对象">检查python对象</a>
                        </li>
                    
                
            
            
            
            
            
            
            
            
            
            
            
                        
                        
                        <li class="toc-li-3">
                            <a href="#文档字符串`__doc__`属性">文档字符串`__doc__`属性</a>
                        </li>
                    
                
            
            
            
            
                        
                        
                        <li class="toc-li-3">
                            <a href="#名称`__name__`属性">名称`__name__`属性</a>
                        </li>
                    
                
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
                        
                        
                        <li class="toc-li-3">
                            <a href="#类型type()">类型type()</a>
                        </li>
                    
                
            
                        
                        
                        <li class="toc-li-3">
                            <a href="#标识id()">标识id()</a>
                        </li>
                    
                
            
                        
                        
                        <li class="toc-li-3">
                            <a href="#检测是否存在属性in/not-in">检测是否存在属性in/not in</a>
                        </li>
                    
                
            
                        
                        
                        <li class="toc-li-3">
                            <a href="#可调用callable()">可调用callable()</a>
                        </li>
                    
                
            
            
            
            
            
                        
                        
                        <li class="toc-li-3">
                            <a href="#实例">实例</a>
                        </li>
                    
                
            
            
                        
                        
                        <li class="toc-li-3">
                            <a href="#子类">子类</a>
                        </li>
                    
                
            
            
            
            
            
                        
                        
                        <li class="toc-li-2">
                            <a href="#python文档">python文档</a>
                        </li>
                    
                
            
            
            
            
            
            
            
            
            </ul>
</div>
  <div tabindex="-1" id="notebook" class="border-box-sizing">
    <div class="container" id="notebook-container">

<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In&nbsp;[1]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="c1"># 打印所有单行变量</span>
<span class="kn">from</span> <span class="nn">IPython.core.interactiveshell</span> <span class="k">import</span> <span class="n">InteractiveShell</span>
<span class="n">InteractiveShell</span><span class="o">.</span><span class="n">ast_node_interactivity</span> <span class="o">=</span> <span class="s1">&#39;all&#39;</span>
</pre></div>

</div>
</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="&#33258;&#30465;">&#33258;&#30465;<a class="anchor-link" href="#&#33258;&#30465;">&#182;</a></h2><blockquote><p>来源<a href="http://www.ibm.com/developerworks/cn/linux/l-pyint/#ibm-pcon">《Python自省指南》</a></p>
</blockquote>
<h3 id="&#32852;&#26426;&#24110;&#21161;">&#32852;&#26426;&#24110;&#21161;<a class="anchor-link" href="#&#32852;&#26426;&#24110;&#21161;">&#182;</a></h3><p>在交互模式下，用help向python请求帮助。</p>

<pre><code>&gt;&gt;&gt; help()

Welcome to Python 3.5's help utility!

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/3.5/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, symbols, or topics, type
"modules", "keywords", "symbols", or "topics".  Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", type "modules spam".

help&gt;</code></pre>
<p>这时候就进入了联机帮助状态，根据提示输入<code>keywords</code></p>

<pre><code>help&gt; keywords

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               def                 if                  raise
None                del                 import              return
True                elif                in                  try
and                 else                is                  while
as                  except              lambda              with
assert              finally             nonlocal            yield
break               for                 not
class               from                or
continue            global              pass</code></pre>
<p>如果从文档说明界面返回到帮助界面，需要按<code>q</code>键。
从联机帮助状态退回到python的交互模式，使用<code>quit</code>命令。</p>

</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="dir()">dir()<a class="anchor-link" href="#dir()">&#182;</a></h3><p>dir() 函数可能是 Python 自省机制中最著名的部分了。它返回传递给它的任何对象的属性名称经过排序的列表。如果不指定对象，则 dir() 返回当前作用域中的名称。</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In&nbsp;[3]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="kn">import</span> <span class="nn">keyword</span>

<span class="nb">dir</span><span class="p">(</span><span class="n">keyword</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">

<div class="prompt output_prompt">Out[3]:</div>




<div class="output_text output_subarea output_execute_result">
<pre>[&#39;__all__&#39;,
 &#39;__builtins__&#39;,
 &#39;__cached__&#39;,
 &#39;__doc__&#39;,
 &#39;__file__&#39;,
 &#39;__loader__&#39;,
 &#39;__name__&#39;,
 &#39;__package__&#39;,
 &#39;__spec__&#39;,
 &#39;iskeyword&#39;,
 &#39;kwlist&#39;,
 &#39;main&#39;]</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In&nbsp;[4]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">__builtins__</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">

<div class="prompt output_prompt">Out[4]:</div>




<div class="output_text output_subarea output_execute_result">
<pre>&lt;module &#39;builtins&#39; (built-in)&gt;</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>注：如果您在磁盘上寻找 <code>__builtin__.py</code> 文件，将空手而归。这个特殊的模块对象是 Python 解释器凭空创建的，因为它包含着解释器始终可用的项。尽管看不到物理文件，但我们仍可以将 dir() 函数应用于这个对象，以观察所有内置函数、错误对象以及它所包含的几个杂项属性。</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In&nbsp;[5]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">dir</span><span class="p">(</span><span class="n">__builtins__</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">

<div class="prompt output_prompt">Out[5]:</div>




<div class="output_text output_subarea output_execute_result">
<pre>[&#39;ArithmeticError&#39;,
 &#39;AssertionError&#39;,
 &#39;AttributeError&#39;,
 &#39;BaseException&#39;,
 &#39;BlockingIOError&#39;,
 &#39;BrokenPipeError&#39;,
 &#39;BufferError&#39;,
 &#39;BytesWarning&#39;,
 &#39;ChildProcessError&#39;,
 &#39;ConnectionAbortedError&#39;,
 &#39;ConnectionError&#39;,
 &#39;ConnectionRefusedError&#39;,
 &#39;ConnectionResetError&#39;,
 &#39;DeprecationWarning&#39;,
 &#39;EOFError&#39;,
 &#39;Ellipsis&#39;,
 &#39;EnvironmentError&#39;,
 &#39;Exception&#39;,
 &#39;False&#39;,
 &#39;FileExistsError&#39;,
 &#39;FileNotFoundError&#39;,
 &#39;FloatingPointError&#39;,
 &#39;FutureWarning&#39;,
 &#39;GeneratorExit&#39;,
 &#39;IOError&#39;,
 &#39;ImportError&#39;,
 &#39;ImportWarning&#39;,
 &#39;IndentationError&#39;,
 &#39;IndexError&#39;,
 &#39;InterruptedError&#39;,
 &#39;IsADirectoryError&#39;,
 &#39;KeyError&#39;,
 &#39;KeyboardInterrupt&#39;,
 &#39;LookupError&#39;,
 &#39;MemoryError&#39;,
 &#39;NameError&#39;,
 &#39;None&#39;,
 &#39;NotADirectoryError&#39;,
 &#39;NotImplemented&#39;,
 &#39;NotImplementedError&#39;,
 &#39;OSError&#39;,
 &#39;OverflowError&#39;,
 &#39;PendingDeprecationWarning&#39;,
 &#39;PermissionError&#39;,
 &#39;ProcessLookupError&#39;,
 &#39;RecursionError&#39;,
 &#39;ReferenceError&#39;,
 &#39;ResourceWarning&#39;,
 &#39;RuntimeError&#39;,
 &#39;RuntimeWarning&#39;,
 &#39;StopAsyncIteration&#39;,
 &#39;StopIteration&#39;,
 &#39;SyntaxError&#39;,
 &#39;SyntaxWarning&#39;,
 &#39;SystemError&#39;,
 &#39;SystemExit&#39;,
 &#39;TabError&#39;,
 &#39;TimeoutError&#39;,
 &#39;True&#39;,
 &#39;TypeError&#39;,
 &#39;UnboundLocalError&#39;,
 &#39;UnicodeDecodeError&#39;,
 &#39;UnicodeEncodeError&#39;,
 &#39;UnicodeError&#39;,
 &#39;UnicodeTranslateError&#39;,
 &#39;UnicodeWarning&#39;,
 &#39;UserWarning&#39;,
 &#39;ValueError&#39;,
 &#39;Warning&#39;,
 &#39;ZeroDivisionError&#39;,
 &#39;__IPYTHON__&#39;,
 &#39;__build_class__&#39;,
 &#39;__debug__&#39;,
 &#39;__doc__&#39;,
 &#39;__import__&#39;,
 &#39;__loader__&#39;,
 &#39;__name__&#39;,
 &#39;__package__&#39;,
 &#39;__spec__&#39;,
 &#39;abs&#39;,
 &#39;all&#39;,
 &#39;any&#39;,
 &#39;ascii&#39;,
 &#39;bin&#39;,
 &#39;bool&#39;,
 &#39;bytearray&#39;,
 &#39;bytes&#39;,
 &#39;callable&#39;,
 &#39;chr&#39;,
 &#39;classmethod&#39;,
 &#39;compile&#39;,
 &#39;complex&#39;,
 &#39;copyright&#39;,
 &#39;credits&#39;,
 &#39;delattr&#39;,
 &#39;dict&#39;,
 &#39;dir&#39;,
 &#39;display&#39;,
 &#39;divmod&#39;,
 &#39;enumerate&#39;,
 &#39;eval&#39;,
 &#39;exec&#39;,
 &#39;filter&#39;,
 &#39;float&#39;,
 &#39;format&#39;,
 &#39;frozenset&#39;,
 &#39;get_ipython&#39;,
 &#39;getattr&#39;,
 &#39;globals&#39;,
 &#39;hasattr&#39;,
 &#39;hash&#39;,
 &#39;help&#39;,
 &#39;hex&#39;,
 &#39;id&#39;,
 &#39;input&#39;,
 &#39;int&#39;,
 &#39;isinstance&#39;,
 &#39;issubclass&#39;,
 &#39;iter&#39;,
 &#39;len&#39;,
 &#39;license&#39;,
 &#39;list&#39;,
 &#39;locals&#39;,
 &#39;map&#39;,
 &#39;max&#39;,
 &#39;memoryview&#39;,
 &#39;min&#39;,
 &#39;next&#39;,
 &#39;object&#39;,
 &#39;oct&#39;,
 &#39;open&#39;,
 &#39;ord&#39;,
 &#39;pow&#39;,
 &#39;print&#39;,
 &#39;property&#39;,
 &#39;range&#39;,
 &#39;repr&#39;,
 &#39;reversed&#39;,
 &#39;round&#39;,
 &#39;set&#39;,
 &#39;setattr&#39;,
 &#39;slice&#39;,
 &#39;sorted&#39;,
 &#39;staticmethod&#39;,
 &#39;str&#39;,
 &#39;sum&#39;,
 &#39;super&#39;,
 &#39;tuple&#39;,
 &#39;type&#39;,
 &#39;vars&#39;,
 &#39;zip&#39;]</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>dir() 函数适用于所有对象类型，包括字符串、整数、列表、元组、字典、函数、定制类、类实例和类方法</p>
<blockquote><p><code>dir(42)</code>,<code>dir([])</code>,<code>dir(())</code>,<code>dir({})</code>,<code>dir(dir)</code></p>
</blockquote>

</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="&#26816;&#26597;python&#23545;&#35937;">&#26816;&#26597;python&#23545;&#35937;<a class="anchor-link" href="#&#26816;&#26597;python&#23545;&#35937;">&#182;</a></h3><p>在计算机术语中，对象是拥有标识和值的事物，属于特定类型、具有特定特征和以特定方式执行操作。并且，对象从一个或多个父类继承了它们的许多属性。除了关键字和特殊符号（像运算符，如 <code>+</code> <code>-</code> <code>*</code> <code>**</code> <code>/</code> <code>%</code> <code>&lt;</code> <code>&gt;</code> 等）外，Python 中的所有东西都是对象。Python具有一组丰富的对象类型：字符串、整数、浮点、列表、元组、字典、函数、类、类实例、模块、文件等。</p>
<p>当您有一个任意的对象（也许是一个作为参数传递给函数的对象）时，可能希望知道一些关于该对象的情况。如希望python告诉我们：</p>
<ul>
<li>对象的名称是什么？</li>
<li>这是哪种类型的对象？</li>
<li>对象知道些什么？</li>
<li>对象能做些什么？</li>
<li>对象的父对象是谁？</li>
</ul>

</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="&#25991;&#26723;&#23383;&#31526;&#20018;__doc__&#23646;&#24615;">&#25991;&#26723;&#23383;&#31526;&#20018;<code>__doc__</code>&#23646;&#24615;<a class="anchor-link" href="#&#25991;&#26723;&#23383;&#31526;&#20018;__doc__&#23646;&#24615;">&#182;</a></h3><p><code>__doc__</code> 这个属性是一个字符串，它包含了描述对象的注释。Python 称之为文档字符串或docstring<br>
如果模块、类、方法或函数定义的第一条语句是字符串，那么该字符串会作为对象的 <code>__doc__</code> 属性与该对象关联起来。</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In&nbsp;[11]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="s1">&#39;python&#39;</span><span class="o">.</span><span class="vm">__doc__</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">

<div class="prompt output_prompt">Out[11]:</div>




<div class="output_text output_subarea output_execute_result">
<pre>&#34;str(object=&#39;&#39;) -&gt; str\nstr(bytes_or_buffer[, encoding[, errors]]) -&gt; str\n\nCreate a new string object from the given object. If encoding or\nerrors is specified, then the object must expose a data buffer\nthat will be decoded using the given encoding and error handler.\nOtherwise, returns the result of object.__str__() (if defined)\nor repr(object).\nencoding defaults to sys.getdefaultencoding().\nerrors defaults to &#39;strict&#39;.&#34;</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In&nbsp;[10]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">print</span><span class="o">.</span><span class="vm">__doc__</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">

<div class="prompt output_prompt">Out[10]:</div>




<div class="output_text output_subarea output_execute_result">
<pre>&#34;print(value, ..., sep=&#39; &#39;, end=&#39;\\n&#39;, file=sys.stdout, flush=False)\n\nPrints the values to a stream, or to sys.stdout by default.\nOptional keyword arguments:\nfile:  a file-like object (stream); defaults to the current sys.stdout.\nsep:   string inserted between values, default a space.\nend:   string appended after the last value, default a newline.\nflush: whether to forcibly flush the stream.&#34;</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="&#21517;&#31216;__name__&#23646;&#24615;">&#21517;&#31216;<code>__name__</code>&#23646;&#24615;<a class="anchor-link" href="#&#21517;&#31216;__name__&#23646;&#24615;">&#182;</a></h3><ul>
<li>如果模块是被导入，<code>__name__</code>的值为模块名字</li>
<li>如果是被直接执行，<code>__name__</code>的值为<code>__main__</code></li>
</ul>
<blockquote><p>此处所说的模块可以简单理解为一个.py文件</p>
</blockquote>
<p>并非所有对象都有名称，但那些有名称的对象都将名称存储在其 <code>__name__</code> 属性中。<br>
注：名称是从对象而不是引用该对象的变量中派生的。</p>

<pre><code>if __name__ == '__main__':
    # Do something appropriate here, like calling a
    # main() function defined elsewhere in this module.
    main()
else:
    # Do nothing. This module has been imported by another
    # module that wants to make use of the functions,
    # classes and other useful bits it has defined.</code></pre>

</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="&#31867;&#22411;type()">&#31867;&#22411;type()<a class="anchor-link" href="#&#31867;&#22411;type()">&#182;</a></h3>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In&nbsp;[12]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">type</span><span class="p">(</span><span class="mi">42</span><span class="p">)</span>   <span class="c1"># --&gt;</span>
<span class="nb">type</span><span class="p">([])</span>   <span class="c1"># --&gt;</span>
<span class="nb">type</span><span class="p">({})</span>   <span class="c1"># --&gt;</span>
<span class="nb">type</span><span class="p">(</span><span class="nb">dir</span><span class="p">)</span>  <span class="c1"># --&gt;</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">

<div class="prompt output_prompt">Out[12]:</div>




<div class="output_text output_subarea output_execute_result">
<pre>int</pre>
</div>

</div>

<div class="output_area">

<div class="prompt output_prompt">Out[12]:</div>




<div class="output_text output_subarea output_execute_result">
<pre>list</pre>
</div>

</div>

<div class="output_area">

<div class="prompt output_prompt">Out[12]:</div>




<div class="output_text output_subarea output_execute_result">
<pre>dict</pre>
</div>

</div>

<div class="output_area">

<div class="prompt output_prompt">Out[12]:</div>




<div class="output_text output_subarea output_execute_result">
<pre>builtin_function_or_method</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="&#26631;&#35782;id()">&#26631;&#35782;id()<a class="anchor-link" href="#&#26631;&#35782;id()">&#182;</a></h3>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In&nbsp;[13]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">id</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">

<div class="prompt output_prompt">Out[13]:</div>




<div class="output_text output_subarea output_execute_result">
<pre>94595642400576</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="&#26816;&#27979;&#26159;&#21542;&#23384;&#22312;&#23646;&#24615;in/not-in">&#26816;&#27979;&#26159;&#21542;&#23384;&#22312;&#23646;&#24615;in/not in<a class="anchor-link" href="#&#26816;&#27979;&#26159;&#21542;&#23384;&#22312;&#23646;&#24615;in/not-in">&#182;</a></h3>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In&nbsp;[15]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="mi">1</span> <span class="ow">in</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span> 
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">

<div class="prompt output_prompt">Out[15]:</div>




<div class="output_text output_subarea output_execute_result">
<pre>True</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In&nbsp;[16]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="mi">1</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span> 
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">

<div class="prompt output_prompt">Out[16]:</div>




<div class="output_text output_subarea output_execute_result">
<pre>False</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="&#21487;&#35843;&#29992;callable()">&#21487;&#35843;&#29992;callable()<a class="anchor-link" href="#&#21487;&#35843;&#29992;callable()">&#182;</a></h3><ol>
<li>callable()方法用来检测对象是否可被调用，可被调用指的是对象能否使用()括号的方法调用。</li>
<li>可调用对象，在实际调用也可能调用失败；但是不可调用对象，调用肯定不成功。</li>
<li>类对象都是可被调用对象，类的实例对象是否可调用对象，取决于类是否定义了<strong>call</strong>方法。</li>
</ol>

</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="&#23454;&#20363;">&#23454;&#20363;<a class="anchor-link" href="#&#23454;&#20363;">&#182;</a></h3><p>在 type() 函数提供对象的类型时，还可以使用 isinstance() 函数测试对象，以确定它是否是某个特定类型或定制类的实例：</p>

</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In&nbsp;[18]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">isinstance</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="nb">list</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">

<div class="prompt output_prompt">Out[18]:</div>




<div class="output_text output_subarea output_execute_result">
<pre>True</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In&nbsp;[20]:</div>
<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">isinstance</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="nb">str</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

<div class="output_wrapper">
<div class="output">


<div class="output_area">

<div class="prompt output_prompt">Out[20]:</div>




<div class="output_text output_subarea output_execute_result">
<pre>False</pre>
</div>

</div>

</div>
</div>

</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h3 id="&#23376;&#31867;">&#23376;&#31867;<a class="anchor-link" href="#&#23376;&#31867;">&#182;</a></h3><p>关于类的问题，有一个“继承”概念，有继承就有父子问题，这是在现实生活中很正常的，在编程语言中也是如此。虽然这是后面要说的，但是，为了本讲内容的完整，也姑且把这个内容放在这里。读者可以不看，留着以后看也行。我更建议还是阅读一下，有个印象。</p>
<p>在类这一级别，可以根据一个类来定义另一个类，同样地，这个新类会按照层次化的方式继承属性。Python 甚至支持多重继承，多重继承意味着可以用多个父类来定义一个类，这个新类继承了多个父类。 issubclass() 函数使我们可以查看一个类是不是继承了另一个类：</p>

</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="python&#25991;&#26723;">python&#25991;&#26723;<a class="anchor-link" href="#python&#25991;&#26723;">&#182;</a></h2><p>1.文档是一种对软件系统的书面描述； 
2.文档应当精确地描述软件系统； 
3.软件文档是软件工程师之间用作沟通交流的一种方式； 
4.文档的类型有很多种，包括软件需求文档，设计文档，测试文档，用户手册等； 
5.文档的呈现方式有很多种，可以是传统的书面文字形式或图表形式，也可是动态的网页形式</p>
<p>python3.5文档的网址：<a href="https://docs.python.org/3.5/">https://docs.python.org/3.5/</a></p>

</div>
</div>
</div>
    </div>
  </div>
</body>

 


</html>
